<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
%>
<%@ page import="cn.edu.scau.cmi.carol.javabean.Conn" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>login_deal</title>
</head>
<body>

<jsp:useBean id="user_login" class="cn.edu.scau.cmi.carol.javabean.User" scope="session"></jsp:useBean>
<jsp:setProperty property="*" name="user_login"/>

<%
    try{
    	session.setAttribute("user_login", user_login);
    	session.getAttribute("user_login");
    	System.out.print(user_login.getName());
    	Connection conn=Conn.connect();
    	String selectsql="select * from student where studentID=?";
    	PreparedStatement ps=conn.prepareStatement(selectsql);
    	ps.setInt(1, user_login.getStudentID());
    	ResultSet rs=ps.executeQuery();
    	if(rs.next()){    		
    		if(rs.getString(5).equals("imadministrator")){
    			response.sendRedirect("adminMain.jsp");
    		}
    		else if(rs.getString(5).equals(user_login.getPassword())){
    			response.sendRedirect("studentMain.jsp");
   	        }
   	        else{
   		        out.print("password_wrong");
    	    }
    	}
   	    else{
   		out.print("haven't_register");
   	    }     	
    	rs.close();
    	ps.close();
    	conn.close();
    }
    catch(Exception e){
    	out.print("failed.");
    	e.printStackTrace();
    }
%>
</body>
</html>